<template>
  <transition name="slide">
    <div class="singer-detall">
      <music-list :songs="songs" :bg-image="bgImage" :title="title"></music-list>
      <player></player>
    </div>
  </transition>
</template>

<script type="text/javascript">
import { mapGetters } from 'vuex'
import { getSingerDetail } from '@/api/singer'
import { ERR_OK } from '@/common/js/common'
import { createSongl } from '@/common/js/song'
import MusicList from '@/components/music-list/music-list'
import Player from '@/components/player/player'
export default {
  computed: {
    ...mapGetters([
      'singer'
    ]),
    bgImage () {
      return this.singer.avatar
    },
    title () {
      return this.singer.name
    }
  },
  data () {
    return {
      songs: []
    }
  },
  methods: {
    _getDetail () {
      if (!this.singer.id) {
        this.$router.push('/clouds')
        return
      }
      getSingerDetail(this.singer.id).then((res) => {
        if (res.status === ERR_OK) {
          this.songs = this._normalizeSongs(res.data.hotSongs)
          console.log(this.songs)
        }
      })
    },
    _normalizeSongs (list) {
      var ret = []
      list.forEach((item) => {
        ret.push(createSongl(item))
      })
      return ret
    }
  },
  created () {
    this._getDetail()
    console.log(this.singer)
  },
  components: {
    MusicList,
    Player
  }
}
</script>

<style scoped less="less">
/*.slide-enter-active, .slide-leave-active {
  transition: all 0.2s
}*/
  /*.slide-enter,.slide-leave-to {
    transform: translate3d(100%, 0, 0);
  }*/
</style>
